import java.util.HashMap;
import java.util.Map;

public class Test2 {
    public int lengthOfLongestSubstring(String s) {
        char[] arr = s.toCharArray();
        Map<Character, Integer> hash = new HashMap<>();
        int left = 0,right = 0,maxLength = 0;
        while(right < arr.length){

            if(hash.containsKey(arr[right])){
                left = Math.max(left, hash.get(arr[right]) + 1);
            }
            hash.put(arr[right],right);
            maxLength = Math.max(maxLength,right - left + 1);
            right++;

        }
        return maxLength;
    }
}
